home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / distributedRenderSession.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  5.3 KB  |  188 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File
  19. // MODIFY THIS AT YOUR OWN RISK
  20. //
  21. // Creation Date:  October 21st 1997
  22. // Author:         antoine
  23. //
  24. //
  25. //  Procedure Name:
  26. //      distributedRenderSession
  27. //
  28. //  Description:
  29. //        distributedRenderSession: Sets the working directory and saves
  30. //    a temporary scene to be used by the dispatcher.
  31. //
  32. //  Input Arguments:
  33. //        None.
  34. //
  35. //  Return Value:
  36. //      None.
  37. //
  38. //  Procedure Name:
  39. //        startDistributedRender
  40. //
  41. //  Description:
  42. //        startDistributedRender: call dispatcher with the good arguments.
  43. //
  44. //  Input Arguments:
  45. //        The temporary scene file name.
  46. //        The file type.
  47. //
  48. //  Return Value:
  49. //      true upon success.
  50. //
  51.  
  52. global string $dispatcherConfigPath = "/etc/config/dispatcher.home";
  53. global string $dispatcherExecutableName = "dispatcher";
  54. global string $dispatcherPath = "";
  55.  
  56. global proc int findDispatcherPath()
  57. {
  58.   global string $dispatcherConfigPath;
  59.   global string $dispatcherExecutableName;
  60.   global string $dispatcherPath;
  61.  
  62.   $dispatcherPath="";
  63.  
  64.   if(file("-q", "-exists", $dispatcherConfigPath))
  65.     {
  66.       // this course is safer because the link to the dispatcher binary 
  67.       // may not be installed in /usr/sbin or /sbin.
  68.       // For NT, I guess we'll have to probe the default binary location..
  69.       string    $dispatcherHome = `system("echo -n `cat " + $dispatcherConfigPath + "`")`;
  70.       $dispatcherPath = $dispatcherHome + "/" + $dispatcherExecutableName;
  71.  
  72.       if(! file("-q","-exists", $dispatcherPath))
  73.         $dispatcherPath="";
  74.     }
  75.   
  76.   if(size($dispatcherPath) == 0)
  77.     {
  78.       error("startDistributedRender: please ask your system manager to install dispatcher\nor refer to URL file:/usr/aw/COM/doc/dispatcher_html/DispatcherExpert.doc.html");
  79.       return false;
  80.     }
  81.  
  82.   return true;
  83. }
  84.  
  85. global proc distributedRenderSession()
  86. {
  87.   if(findDispatcherPath())
  88.     {
  89.       string    $workspace = `workspace -q -fn`;
  90.  
  91.       setWorkingDirectory $workspace "mayaBinary" "scene";
  92.       fileBrowser startDistributedRender "Save/Render" mayaBinary 1;
  93.     }
  94. }
  95.  
  96. global proc int startDistributedRender
  97.  ( string    $fileName,
  98.    string    $fileType )
  99. {
  100.   if (`about -evalVersion`)
  101.     {
  102.       error("startDistributedRender: Distributed rendering is not supported\n"+
  103.             "by the Personal Learning Edition of Maya.");
  104.       return false;
  105.     }
  106.  
  107.   if(findDispatcherPath())
  108.     {
  109.       global string $dispatcherPath;
  110.  
  111.       //
  112.       //    Save the file.
  113.       //
  114.       string    $renderFile = `file -ea -typ $fileType $fileName`;
  115.  
  116.       //
  117.       //    Run the dispatchMayaRenderScript...
  118.       //
  119.       if( size($renderFile) > 0 
  120.           && file("-q", "-exists", $renderFile))
  121.         {
  122.           //
  123.           //    Get the render globals.
  124.           //
  125.           string    $glob[] = `ls -rg`;
  126.  
  127.           if( size($glob) > 0 && size($glob[0]) > 0 )
  128.             {
  129.               int    $anim = `getAttr ($glob[0]+".animation")`;
  130.               int    $range = `getAttr ($glob[0]+".animationRange")`;
  131.               int    $start, $end;
  132.  
  133.               //
  134.               //    Get the animation range (from the render globals or from the
  135.               //    range controler).
  136.               //
  137.               if( $anim == 1 && $range == 0 )
  138.                 {
  139.                   $start = `getAttr ($glob[0]+".startFrame")`;
  140.                   $end = `getAttr ($glob[0]+".endFrame")`;
  141.                 }
  142.               else
  143.                 {
  144.                   $start = `playbackOptions -q -minTime`;
  145.                   $end = `playbackOptions -q -maxTime`;
  146.                 }
  147.  
  148.               //
  149.               //    Build the job name based on the script file name.
  150.               //
  151.               string    $list[];
  152.               int        $n = tokenize( $renderFile, "/", $list );
  153.               string    $jobName = $list[$n-1];
  154.  
  155.               //
  156.               //    Get the root project path.
  157.               //
  158.               string    $rootDir = `workspace -q -rd`;
  159.  
  160.               //
  161.               //    Execute the command in background (i.e redirect the outputs).
  162.               //    It calls dispatcher with the following arguments:
  163.               //
  164.               //     -n $start $end 10    //    animation range to be computed
  165.               //                        //    10 is the default number of images
  166.               //                        //    to be computed on a per job basis.
  167.               //     -g                    //    dispatcher comes up in gui mode to
  168.               //                        //    edit the job parameters.
  169.               //     -j string            //    Job name.
  170.               //     -c command            //    command to execute.
  171.               //
  172.               string    $command = ($dispatcherPath + " -n "+$start+" "+$end+" 10 -g -j "+$jobName+" -c \"dispatch_maya_render # "+$end+" 10 -proj "+$rootDir+" "+$renderFile+"\" >/dev/null 2>&1 &");
  173.  
  174.               system( $command );
  175.  
  176.               string    $currentDir = `workspace -q -dir`;
  177.               retainWorkingDirectory( $currentDir );
  178.  
  179.               return true;
  180.             }
  181.         }
  182.       else
  183.         error("startDistributedRender: no renderable scene given");
  184.     }
  185.  
  186.   return false;
  187. }
  188.